package com.changdu.seatunnel.admin.config.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

@Getter
public enum SyncTaskStatus {
	
    PENDING(0, "待执行", "PENDING"),
    IN_PROGRESS(1, "执行中", "RUNNING"),
    COMPLETED(2, "已完成", "FINISHED"),
    FAILED(3, "失败", "FAILED"),
	STOP(4, "已停止", "STOP"),
	DOING_SAVEPOINT(4, "已停止", "DOING_SAVEPOINT"),
	NOT_EXISTS(5, "已退出或不存在", "NOT_EXISTS")
	;
	
    @EnumValue
    private final int code;
    private final String description;
    private final String seatunnelStatus;

    SyncTaskStatus(int code, String description, String seatunnelStatus) {
        this.code = code;
        this.description = description;
        this.seatunnelStatus = seatunnelStatus;
    }

	public static SyncTaskStatus fromCode(int code) {
		for (SyncTaskStatus status : SyncTaskStatus.values()) {
			if (status.code == code) {
				return status;
			}
		}
		throw new IllegalArgumentException("Unknown code: " + code);
	}
	
	public static SyncTaskStatus fromSeatunnelStatus(String seatunnelStatus) {
		for (SyncTaskStatus status : SyncTaskStatus.values()) {
			if (status.seatunnelStatus.equals(seatunnelStatus)) {
				return status;
			}
		}
		throw new IllegalArgumentException("Unknown code: " + seatunnelStatus);
	}	
}